
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>pypcd.pdutil &#8212; pypcd 0.1.1 documentation</title>
    <link rel="stylesheet" href="../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
   
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for pypcd.pdutil</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">pypcd</span>


<div class="viewcode-block" id="data_frame_to_point_cloud"><a class="viewcode-back" href="../../pypcd.html#pypcd.pdutil.data_frame_to_point_cloud">[docs]</a><span class="k">def</span> <span class="nf">data_frame_to_point_cloud</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; create a PointCloud object from a dataframe.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pc_data</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">to_records</span><span class="p">(</span><span class="n">index</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
    <span class="n">md</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;version&#39;</span><span class="p">:</span> <span class="o">.</span><span class="mi">7</span><span class="p">,</span>
          <span class="s1">&#39;fields&#39;</span><span class="p">:</span> <span class="p">[],</span>
          <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="p">[],</span>
          <span class="s1">&#39;count&#39;</span><span class="p">:</span> <span class="p">[],</span>
          <span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
          <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
          <span class="s1">&#39;viewpoint&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span>
          <span class="s1">&#39;points&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
          <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="p">[],</span>
          <span class="s1">&#39;data&#39;</span><span class="p">:</span> <span class="s1">&#39;binary_compressed&#39;</span><span class="p">}</span>
    <span class="n">md</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="n">md</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]:</span>
        <span class="n">type_</span><span class="p">,</span> <span class="n">size_</span> <span class="o">=</span>\
            <span class="n">pypcd</span><span class="o">.</span><span class="n">numpy_type_to_pcd_type</span><span class="p">[</span><span class="n">pc_data</span><span class="o">.</span><span class="n">dtype</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="n">field</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span>
        <span class="n">md</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">type_</span><span class="p">)</span>
        <span class="n">md</span><span class="p">[</span><span class="s1">&#39;size&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">size_</span><span class="p">)</span>
        <span class="c1"># TODO handle multicount</span>
        <span class="n">md</span><span class="p">[</span><span class="s1">&#39;count&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">md</span><span class="p">[</span><span class="s1">&#39;width&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">pc_data</span><span class="p">)</span>
    <span class="n">md</span><span class="p">[</span><span class="s1">&#39;points&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">pc_data</span><span class="p">)</span>
    <span class="n">pc</span> <span class="o">=</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">PointCloud</span><span class="p">(</span><span class="n">md</span><span class="p">,</span> <span class="n">pc_data</span><span class="p">)</span></div>
    <span class="k">return</span> <span class="n">pc</span>


<div class="viewcode-block" id="data_frame_to_message"><a class="viewcode-back" href="../../pypcd.html#pypcd.pdutil.data_frame_to_message">[docs]</a><span class="k">def</span> <span class="nf">data_frame_to_message</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">stamp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">frame_id</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="n">pc_data</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">to_records</span><span class="p">(</span><span class="n">index</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pypcd</span><span class="o">.</span><span class="n">numpy_pc2</span><span class="o">.</span><span class="n">array_to_pointcloud2</span><span class="p">(</span><span class="n">pc_data</span><span class="p">,</span>
                                                <span class="n">stamp</span><span class="o">=</span><span class="n">stamp</span><span class="p">,</span></div>
                                                <span class="n">frame_id</span><span class="o">=</span><span class="n">frame_id</span><span class="p">)</span>
</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../index.html">Documentation overview</a><ul>
  <li><a href="../index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2018, Daniel Maturana.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.1</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
    </div>

    

    
  </body>
</html>